$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'bss/apwire/list?state=isdelno&pGuid='+ GetUrlParam("guid"),
        datatype: "json",
        colModel: [			
			{ label: 'guid', name: 'guid', index: 'guid', width: 50, key: true,hidden: true },
			{ label: '所属项目ID', name: 'pGuid', index: 'p_guid', width: 200,hidden: true  },
			{ label: '导线材料ID', name: 'pMGuid', index: 'p_m_guid', width: 200 ,hidden: true },
			{ label: '材料名称', name: 'pWName', index: 'p_w_name', width: 200 },
            { label: '导线类型', name: 'wiretype', index: 'wiretype', width: 100 },
            { label: '导线线径', name: 'wirediam', index: 'wirediam', width: 100 },
			{ label: '数据状态', name: 'pWDatastate', index: 'p_w_datastate', width: 200 }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
    $("#jqGrid1").jqGrid({
        url: baseURL + 'api/bmaterial/listwire',
        datatype: "json",
        colModel: [
            {label: 'guid', name: 'guid', index: 'guid', width: 50, key: true, hidden: true},
            {label: '物质编码', name: 'mCode', index: 'm_code', width: 80},
            {label: '材料大类', name: 'mBigtype', index: 'm_bigtype', width: 80},
            {label: '材料中类', name: 'mMidtype', index: 'm_midtype', width: 80},
            {label: '材料标签', name: 'mLabel', index: 'm_label', width: 80},
            {label: '材料名称', name: 'mName', index: 'm_name', width: 200}

        ],
        viewrecords: true,
        height: "100%",
        width:"100%",
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager1",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid1").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });



});
function getSelectedRows1() {
    var grid = $("#jqGrid1");
    var rowKey = grid.getGridParam("selrow");
    if (!rowKey) {
        alert("请选择一条记录");
        return;
    }

    return grid.getGridParam("selarrrow");
}
var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		aPWire: {},
		q:{
           mCode:null,
            mName:null,
		}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";




        },
		update: function (event) {
			var guid = getSelectedRow();
			if(guid == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(guid)
		},
        selectwire: function (event) {
            var guids = getSelectedRows1();
            if(guids == null){
                return ;
            }
          var guid= (GetUrlParam("guid"));
            var url = "bss/apwire/saveselect/"+guid ;
            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/json",
                data: JSON.stringify(guids),

                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(index){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });

        },

		saveOrUpdate: function (event) {
			var url = vm.aPWire.guid == null ? "bss/apwire/save" : "bss/apwire/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.aPWire),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var guids = getSelectedRows();
			if(guids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "bss/apwire/delete",
                    contentType: "application/json",
				    data: JSON.stringify(guids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(guid){
			$.get(baseURL + "bss/apwire/info/"+guid, function(r){
                vm.aPWire = r.aPWire;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		},
        reloadwire: function (event) {

            var page = $("#jqGrid1").jqGrid('getGridParam','page');
            $("#jqGrid1").jqGrid('setGridParam',{
                postData: {
                    'mCode': vm.q.mCode,
					'mName': vm.q.mName

                },
                page:page
            }).trigger("reloadGrid");
        }

	}
});